// cookie
function getCookie(name) {
    // (^| )name=([^;]*)(;|$),match[0]为与整个正则表达式匹配的字符串，match[i]为正则表达式捕获数组相匹配的数组；
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) {
        return unescape(arr[2]);
    }
    return null;
}
function setCookie(name,value) {
    var Days = 10; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    if((typeof value == "string")&&(value.length > 0)){
        document.cookie = name + "="+ escape(value) + ";expires=" + exp.toGMTString();
    }else{
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getCookie(name);
        if(cval!=null)
            document.cookie=name +"="+cval+";expires="+exp.toGMTString();
    }
}



$(document).ready(function () {
    let screenWidth = window.innerWidth;
    // let screenHeight = document.body.clientWidth
    $(window).resize(function () {
// else if ((document.body) && (document.body.clientWidth))
        screenWidth = document.body.clientWidth;
        // screenHeight = $(window).height()
        initSize();
    })
    function initSize() {
        drawContent()
        countHieght()
    }

    function countHieght(){
        var itemLength = $('.container-list').children('a').length
        if(screenWidth>767&&screenWidth<1025){
            $('.footer').css('margin-top','-120px')
        } else if (screenWidth>1025&&screenWidth<1281) {
            if (itemLength > 9) {
                // let containerHeight = itemLength%3 !== 0?Math.ceil(itemLength/3) * 120  : (itemLength/3) * 120
                // $('.container-list').css('height',containerHeight + 24)
                $('.container').css('height','650px')
                $('.footer').css('margin-top','30px')

            }else{
                // let mainHeight = window.innerHeight - $('.header').height() - $('.footer').height()
                // $('#main').css('height',mainHeight)
                $('.footer').css('margin-top','-100px')
                $('.container').css('height','550px')
            }
        }else{
            if (itemLength > 12) {
                // let containerHeight = itemLength%3 !== 0?(itemLength/3 + 1) * 120  : (itemLength/3) * 120
                // $('.container-list').css('height',containerHeight + 24)
                $('.footer').css('margin-top','20px')
                $('.container').css('height','825px')
            }else{
                // let mainHeight = window.innerHeight - $('.header').height() - $('.footer').height()
                // $('#main').css('height',mainHeight)
                $('.footer').css('margin-top','-120px')
                $('.container').css('height','770px')

            }
        }
    }
    function drawContent(){
        if(screenWidth>0&&screenWidth<767){
            $('.header-logo').css("margin-left","10px")
            $('.container').css('width','320px')
            $('.container-list').css('width','320px')
            $('.container-title').css("padding-top","0")
            $('.container-title').css("text-align","center")
            $('.container-list-content').css('width','300px')
            $('.container-list-content').css('padding-left','20px')
            $('.footer').css('width','270px')
            $('.footer').css('line-height','30px')
            $('.footer-company, .footer-copy').css('float','right')
        }else if(screenWidth>767&&screenWidth<1025){
            $('.header-logo').css("margin-left","20px")
            $('.container').css('width','720px')
            $('.container-list').css('width','740px')
            $('.container-list-content.right').css('margin-right','20px')
            $('.container-title').css("text-align","left")
            $('.footer').css('width','462.52px')
            $('.footer').css('line-height','80px')
            $('.footer-company, .footer-copy').css('float','left')
        } else if(screenWidth>1025&&screenWidth<1281){
            $('.header').css("height","134px")
            $('.header-logo').css("margin-left","50px")
            $('.container').css("padding-bottom","54px")
            $('.container').css('width','1080px')
            $('.container-title').css("padding-top","0")
            $('.container-title').css("text-align","left")
            $('.container-list-content').css('width','347px')
            $('.container-list-content').css('padding-left','0')
            $('.container-list-content.right').css('width','346px')
            $('.container-list-content.right').css('margin-right','0')
            $('.container-list').css("padding-top","30px")
            $('.container-list').css('width','1080px')
            $('.footer').css('width','462.52px')
            $('.footer').css('line-height','80px')
            $('.footer-company, .footer-copy').css('float','left')
        }else if(screenWidth>1281){
            $('.header').css("height","140px")
            $('.header-logo').css("margin-left","50px")
            $('.container').css("padding-bottom","60px")
            $('.container').css('width','1080px')
            $('.container-title').css("text-align","left")
            $('.container-list-content').css('width','347px')
            $('.container-list-content').css('padding-left','0')
            $('.container-list-content.right').css('width','346px')
            $('.container-list-content.right').css('margin-right','0')
            $('.container-list').css("padding-top","60px")
            $('.container-list').css('width','1080px')
            $('.footer').css('width','462.52px')
            $('.footer').css('line-height','80px')
            $('.footer-company, .footer-copy').css('float','left')
        }
    }
    drawContent()
    countHieght()
});
